/*
	背景js，扩展全局的js
*/
// A generic onclick callback function.
function genericOnClick(info, tab) {
	console.log("selected text: " + info.selectionText );
	console.log("item " + info.menuItemId + " was clicked");
	console.log("info: " + JSON.stringify(info));
	console.log("tab: " + JSON.stringify(tab));

	// 创建一个简单的文字通知：
	var notification = webkitNotifications.createNotification(
	  '48.png',  // icon url - can be relative
	  'Hello!',  // notification title
	  'Lorem ipsum...'  // notification body text
	);
	// 显示通知
	notification.show();
}

function searchByBaidu(info, tab) {
	var keyword = info.selectionText;
	chrome.tabs.create({"url":"http://www.baidu.com/s?wd="+keyword});
}

// Create one test item for each context type.
var contexts = ["page","selection","link","editable","image","video", "audio"];
//var id = chrome.contextMenus.create({"title": 'hell Menu', "contexts":contexts,"onclick": genericOnClick});
var baiduSearchMenu = chrome.contextMenus.create({"title": '用百度搜索 “%s”', "contexts":["selection"], "documentUrlPatterns":["*://www.google.com.hk/*"], "onclick": searchByBaidu});
console.log("item:" + baiduSearchMenu);

chrome.tabs.onCreated.addListener(function(tab) {
  console.log('tabs.onCreated --'
              + ' window: ' + tab.windowId
              + ' tab: '    + tab.id
              + ' index: '  + tab.index
              + ' url: '    + tab.url);
});
